<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('合作商列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label style="width: 90px;">合作商类型：</label>
                            <select name="subjectType" th:with="type=${@dict.getType('sys_partner_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label style="width: 90px;">选择合作商：</label>
                            <input id="treeId" name="id" style="display: none;"/>
                            <input type="text" onclick="selectPartnerTree()" id="treeName" placeholder="点击选择合作商"
                                   readonly="true">
                        </li>
                        <li class="select-time">
                            <label>签约时间：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="fullName" selected>合作商姓名</option>
                                <option value="phone">合作商联系方式</option>
                                <option value="superiorFullName">上级合作商姓名</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:partner:add">
                <i class="fa fa-plus"></i> 添加(顶级)合作商
            </a>
            <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()"-->
            <!--shiro:hasPermission="system:partner:edit">-->
            <!--<i class="fa fa-edit"></i> 修改-->
            <!--</a>-->
            <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"-->
            <!--shiro:hasPermission="system:partner:remove">-->
            <!--<i class="fa fa-remove"></i> 删除-->
            <!--</a>-->
            <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:partner:export">-->
            <!--<i class="fa fa-download"></i> 导出-->
            <!--</a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:partner:edit')}]];

    var statisticalAnalysisFlag = [[${@permission.hasPermi('system:partner:statisticalAnalysis')}]]; // 统计分析
    var devIncomeFlag = [[${@permission.hasPermi('system:partner:devIncome')}]]; // 设备营业额列表展示

    var removeFlag = [[${@permission.hasPermi('system:partner:remove')}]];

    var seeDetailFlag = [[${@permission.hasPermi('system:partner:seeDetail')}]];
    var putUpBaseFlag = [[${@permission.hasPermi('system:partner:putUpBase')}]];

    var subjectTypeDatas = [[${@dict.getType('sys_partner_type')}]];
    var prefix = ctx + "system/partner";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "合作商",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'fullName',
                    title: '合作商姓名',
                    formatter: function (value, row, index) {
                        return value + "(" + $.table.selectDictLabel(subjectTypeDatas, row.subjectType) + ")";
                    }
                },
                {
                    field: 'phone',
                    title: '合作商联系方式'
                },
                // {
                //     field: 'subjectType',
                //     title: '合作商类型',
                //     formatter: function (value, row, index) {
                //         return $.table.selectDictLabel(subjectTypeDatas, value);
                //     }
                // },
                {
                    field: 'parentFullName',
                    title: '上级合作商'
                },
                {
                    field: 'cashoutMoney',
                    title: '可提现金额'
                },
                {
                    field: 'frozenMoney',
                    title: '已冻结金额'
                },
                {
                    field: 'signingTime',
                    title: '签约时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];


                        // 平台可以编辑顶级合作商，但是不能编辑下级的合作商
                        if (row.parentId == "" || row.parentId == null || row.parentId == '0') {
                            // 为顶级合作商，可编辑
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }

                        actions.push('<a class="btn btn-default btn-xs ' + seeDetailFlag + '" href="javascript:void(0)" onclick="seeTier(\'' + row.id + '\')"><i class="fa fa-navicon"></i>查看层级关系</a> ');

                        actions.push('<a class="btn btn-primary btn-xs ' + seeDetailFlag + '" href="javascript:void(0)" onclick="seeDetail(\'' + row.id + '\')"><i class="fa fa-edit"></i>查看详情</a> ');

                        actions.push('<a class="btn btn-info btn-xs ' + putUpBaseFlag + '" href="javascript:void(0)" onclick="putUpBase(\'' + row.id + '\')"><i class="fa fa-gear"></i>设置</a> ');

                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>解约</a> ');


                        actions.push('<a class="btn btn-info btn-xs ' + statisticalAnalysisFlag + '" href="javascript:void(0)" onclick="statisticalAnalysisView(\'' + row.id + '\')"><i class="fa fa-gear"></i>统计分析</a> ');

                        actions.push('<a class="btn btn-primary btn-xs ' + devIncomeFlag + '" href="javascript:void(0)" onclick="devIncomes(\'' + row.id + '\')"><i class="fa fa-gear"></i>设备营业额</a> ');

                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    function devIncomes(id) {
        var url = prefix + "/devIncomes/" + id;
        var width = null;
        var height = null;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 1200;
        }
        if ($.common.isEmpty(height)) {
            height = 660;
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "设备营业额",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function (index) {
                return true;
            }
        });
    }

    // 统计分析
    function statisticalAnalysisView(id) {
        var url = prefix + "/statisticalAnalysis/" + id;
        var width = null;
        var height = null;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 1200;
        }
        if ($.common.isEmpty(height)) {
            height = 800;
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "统计分析",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function (index) {
                return true;
            }
        });
    }

    // 查看详情
    function seeDetail(id) {
        var url = prefix + "/seeDetail/" + id;
        var width = null;
        var height = null;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 800;
        }
        if ($.common.isEmpty(height)) {
            height = 660;
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "查看详情",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function (index) {
                return true;
            }
        });
    }

    /*合作商-新增-选择父部门树*/
    function selectPartnerTree() {
        var options = {
            title: '合作商选择',
            width: "380",
            url: prefix + "/selectPartnerTree/" + $("#treeId").val(),
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = layer.getChildFrame('body', index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        layer.close(index);
    }


    // 基础设置
    function putUpBase(id) {
        var url = prefix + "/putUpBase/" + id;
        $.modal.open("设置", url, 800, 460);
    }

    function seeTier(id) {
        // 仅展示该合作商的上级跟下级
        var url = prefix + "/selectPartnerTreeForSelf/" + id;
        var width = null;
        var height = null;
        if ($.common.isMobile()) {
            width = 'auto';
            height = 'auto';
        }
        if ($.common.isEmpty(url)) {
            url = "/404.html";
        }
        if ($.common.isEmpty(width)) {
            width = 500;
        }
        if ($.common.isEmpty(height)) {
            height = 660;
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: "层级关系",
            content: url,
            btn: ['关闭'],
            // 弹层外区域关闭
            shadeClose: true,
            cancel: function (index) {
                return true;
            }
        });
    }

</script>
</body>
</html>